package com.opengisagrario;

import com.opengisagrario.utils.GestionParcelasItems;
import com.opengisagrario.utils.ItemAdapter;
import com.opengisagrario.utils.ItemAdapterParcelas;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;

public class GestionParcelasActivity extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_gestion_parcelas);
		populateList();
		registerOnItemClick();
	}

    private void registerOnItemClick() {
    	ListView listView = (ListView) findViewById(R.id.listViewGestionParcelas);
    	listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> parent, View viewClicked,int position, long id) {
				switch(position){
					case 0:
						break;
					case 1:
						Intent intentCrearParcela = new Intent(GestionParcelasActivity.this, CrearParcelaActivity.class);
						startActivity(intentCrearParcela);
						break;
				}
				
			}
    		
    	});
		
	}

	public void populateList(){
		GestionParcelasItems.LoadGestionParcelasItems();
		ListView listView = (ListView) findViewById(R.id.listViewGestionParcelas);
		String[] ids = new String[GestionParcelasItems.Items.size()];
		for (int i= 0; i < ids.length; i++){
            ids[i] = Integer.toString(i+1);
        }
		ItemAdapterParcelas adapter = new ItemAdapterParcelas(this,R.layout.items, ids);
        listView.setAdapter(adapter);
    }
    
}